package com.tw;

/**
 * Created by dhanesharole on 6/17/14.
 */

import java.util.ArrayList;

/**
 * Created by dhanesharole on 6/17/14.
 * This is last program from assignment
 */
public class PrimeFactor {
    public static void main(String[] args) {
        int n = 30;
        ArrayList<Integer> a = new ArrayList<Integer>();
        a = PrimeFactor.generate(n);
        for (int i : a) {
            System.out.println(i);
        }
    }

    private static ArrayList<Integer> generate(int n) {
        int i;
        ArrayList<Integer> a = new ArrayList<Integer>();
        if (n == 1 || n == 2) {
            return a;
        }
        for (i = 2; i < n; i++) {
            if (n % i == 0 && IsPrime(i)) {
                a.add(i);
            }
        }
        return a;
    }

    private static boolean IsPrime(int n) {
        int j;
        for (j = 2; j < (Integer) (n / 2); j++) {
            if (n % j == 0) {
                return false;
            }
        }
        return true;
    }
}